home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
- * *
- * This is the selftree-include-file for POVRay. *
- * c1997 by Stephan Kuhagen *
- * *
- * Description: the include-file generates another include-file which *
- * generates a recursive tree-object. Has thousands of parameters *
- * (which is not a feature, but not a bug also... I think...) and *
- * is very diffcult to use (but better than constructing your trees *
- * by hand) and takes a millennium to render... You be warned. *
- * *
- * Usage: define many many variables, then include selftree.inc and *
- * then include the tree-include which you have made with *
- * -GDFILENAME and say object { OBJECTNAME }. *
- * The include has reasonable defaults, but you can find much better *
- * values for more realistic trees. Look at the documentation and *
- * the example-files included in the distribution. *
- * *
- * Copyright: You may use it, as you like. If you want to distribute *
- * the include, ask me for permission, I will give you... *
- * *
- *********************************************************************/
-
-
-
- /*********************************************************************
- * *
- * Set default-values for the variables *
- * *
- *********************************************************************/
-
-
- #ifndef ( OBJECTNAME)
- #declare OBJECTNAME = "TREE" // Name of the tree-object (STRING)
- #end
-
- #ifndef ( USESTDTRUNK)
- #declare USESTDTRUNK = "YES" // Should we use the predefined trunk? (BOOL: YES/NO)
- #end
-
- #ifndef ( TRUNKLEN)
- #declare TRUNKLEN = "5" // How long should the trunk be? (FLOAT, >0)
- #end
-
- #ifndef ( TRUNKBASER)
- #declare TRUNKBASER = "0.7" // The trunk-radius at the floor. (FLOAT, >0)
- #end
-
- #ifndef ( TRUNKCAPR)
- #declare TRUNKCAPR = "0.5" // The trunk-radius at the top. (FLOAT, >0)
- #end
-
- #ifndef ( DEPTH)
- #declare DEPTH = 6 // The recursion-depth (use with care!) (INT, >0)
- #end
-
- #ifndef ( BLEN)
- #declare BLEN = "5" // The length of a branch in the first recursion-step (minimum) (FLOAT, >0)
- #end
-
- #ifndef ( LDIFF)
- #declare LDIFF = "0" // A difference for the branch-legth (would be added to BLEN) (FLOAT, LDIFF> -BLEN)
- #end
-
- #ifndef ( RADIUS)
- #declare RADIUS = "0.5" // The start radius for the branches (FLOAT, >0)
- #end
-
- #ifndef ( RADSCALE)
- #declare RADSCALE = "0.5" // The scale for the branch-radius (FLOAT, >0)
- #end
-
- #ifndef ( RDIFF)
- #declare RDIFF = "0" // A difference for the branch-radius (would be subtracted from RADIUS) (FLOAT, |RDIFF|<RADIUS)
- #end
-
- #ifndef ( RECSCALE)
- #declare RECSCALE = "0.5" // The scale for the recursion (FLOAT, >0)
- #end
-
- #ifndef ( SLOPEANGLE)
- #declare SLOPEANGLE = "40" // The slope-angle for the branches (FLOAT)
- #end
-
- #ifndef ( SANGLEDIFF)
- #declare SANGLEDIFF = "0" // A difference for the slope-angle (would be added to SLOPEANGLE) (FLOAT)
- #end
-
- #ifndef ( ANGLESCALE)
- #declare ANGLESCALE = "1.1" // The scale for the for the slope-angle (FLOAT)
- #end
-
- #ifndef ( NRBRANCHES)
- #declare NRBRANCHES = "4" // The number of branches (INT, >0)
- #end
-
- #ifndef ( NRBDIFF)
- #declare NRBDIFF = "0" // A difference for the number of branches (would be added to NRBRANCHES) (FLOAT)
- #end
-
- #ifndef ( NRBSCALEADD)
- #declare NRBSCALEADD = "0" // A scale for the number of branches (would be added to NRBRANCHES addiert)(FLOAT)
- #end
-
- #ifndef ( NRBSCALEMUL)
- #declare NRBSCALEMUL = "1" // Another scale for the number of branches (would be multiplied with NRBRANCHES)(FLOAT)
- #end
-
- #ifndef ( BRANCHTOP)
- #declare BRANCHTOP = "0.6" // The chance for a branch to sit at the top of its parent or randomly at another place. (FLOAT, 0<=x<=1)
- #end
-
- #ifndef ( LEAFINC)
- #declare LEAFINC = "NO" // Are there leafs? (STRING, YES|NO)
- #end
-
- #ifndef ( NRLEAFINCS)
- #declare NRLEAFINCS = 0 // How many leafs are there? (INT, >=0)
- #end
-
- #ifndef ( NRLEAFS)
- #declare NRLEAFS = "0" // Number of leafs per branch (INT, >=0)
- #end
-
- #ifndef ( NRLDIFF)
- #declare NRLDIFF = "0" // A difference for the number of leafs (would be added to NRLEAFS)(INT, NRLDIFF> -NRLEAFS)
- #end
-
- #ifndef ( ROTRANGE)
- #declare ROTRANGE = "360" // The range for the rotation-angle of the branches (FLOAT, 0<=x<=360)
- #end
-
- #ifndef ( RANDINIT_ROT)
- #declare RANDINIT_ROT = "1.1234" // The startvalue for the random-generator for rotations (FLOAT)
- #end
-
- #ifndef ( RANDINIT_LDIFF)
- #declare RANDINIT_LDIFF = "0.1234" // The startvalue for the random-generator for LDIFF (FLOAT)
- #end
-
- #ifndef ( RANDINIT_RDIFF)
- #declare RANDINIT_RDIFF = "0.1234" // The startvalue for the random-generator for RDIFF (FLOAT)
- #end
-
- #ifndef ( RANDINIT_SDIFF)
- #declare RANDINIT_SDIFF = "0.1234" // The startvalue for the random-generator for SANGLEDIFF (FLOAT)
- #end
-
- #ifndef ( RANDINIT_NRBDIFF)
- #declare RANDINIT_NRBDIFF = "0.1234" // The startvalue for the random-generator for NRBDIFF (FLOAT)
- #end
-
- #ifndef ( RANDINIT_NRLDIFF)
- #declare RANDINIT_NRLDIFF = "0.1234" // The startvalue for the random-generator for NRLDIFF (FLOAT)
- #end
-
- #ifndef ( RANDINIT_LEAFSELECT)
- #declare RANDINIT_LEAFSELECT = "0.1234" // The startvalue for the random-generator for the selection of leafs. (FLOAT)
- #end
-
- #ifndef ( RANDINIT_LEAFTRANS)
- #declare RANDINIT_LEAFTRANS = "0.1234" // The startvalue for the random-generator for the placing of the leafs on the braches. (FLOAT)
- #end
-
- #ifndef ( RANDINIT_LEAFROT)
- #declare RANDINIT_LEAFROT = "0.1234" // The startvalue for the random-generator for the rotation of the leafs. (FLOAT)
- #end
-
- #ifndef ( RANDINIT_BT)
- #declare RANDINIT_BT = "0.1234" // The startvalue for the random-generator for BRANCHTOP (FLOAT)
- #end
-
- // Default-Texture, you should always have one
- #default { pigment { color rgb <0.35, 0.16, 0.14> } }
-
-
-
- /*********************************************************************
- **********************************************************************
- **********************************************************************
- *** ***
- *** DO NOT CHANGE ANYTHING BELOW HERE ***
- *** ***
- **********************************************************************
- **********************************************************************
- *********************************************************************/
-
-
-
- /*********************************************************************
- * *
- * Now produce the tree-include and write it to the debug-stream *
- * *
- *********************************************************************/
-
-
- #debug "/*********************************************************************\n"
- #debug "\n"
- #debug concat(" Objectname: ",OBJECTNAME,"\n")
- #debug "\n"
- #debug "*********************************************************************/\n\n"
-
- // Initializing the random-streams
- #debug concat("#declare RANDROT_",OBJECTNAME," = seed(",RANDINIT_ROT,") // random for rotation\n")
- #debug concat("#declare RANDLDIFF_",OBJECTNAME," = seed(",RANDINIT_LDIFF,") // random for LDIFF\n")
- #debug concat("#declare RANDRDIFF_",OBJECTNAME," = seed(",RANDINIT_RDIFF,") // random for RDIFF\n")
- #debug concat("#declare RANDSDIFF_",OBJECTNAME," = seed(",RANDINIT_SDIFF,") // random for SANGLEDIFF\n")
- #debug concat("#declare RANDNRBDIFF_",OBJECTNAME," = seed(",RANDINIT_NRBDIFF,") // random for NRBDIFF\n")
- #debug concat("#declare RANDNRLDIFF_",OBJECTNAME," = seed(",RANDINIT_NRLDIFF,") // random for NRLDIFF\n")
- #debug concat("#declare RANDLEAFROT_",OBJECTNAME," = seed(",RANDINIT_LEAFROT,") // random for LEAFROT\n")
- #debug concat("#declare RANDLEAFTRANS_",OBJECTNAME," = seed(",RANDINIT_LEAFTRANS,") // random for LEAFTRANS\n")
- #debug concat("#declare RANDLEAFSELECT_",OBJECTNAME," = seed(",RANDINIT_LEAFSELECT,") // random for LEAFSELECT\n")
- #debug concat("#declare RANDBT_",OBJECTNAME," = seed(",RANDINIT_BT,") // random for BRANCHTOP\n\n")
-
-
-
- // Set up some Vars for Statistics
- // How many cones
- #debug "#declare NROFCONES = 0\n"
- // How many spheres
- #debug "#declare NROFSPHERES = 0\n"
- // How many leafs
- #debug "#declare NROFLEAFS = 0\n\n"
-
-
-
- // Open the union OBJECTNAME
- #declare INCDEPTH = 0
- #debug concat("#declare X = ",str(INCDEPTH,0,0),"\n")
- #debug "\n"
- #debug concat("#declare ",OBJECTNAME," =\n")
- #debug "union\n"
- #debug "{\n"
- #debug " // Generate the trunk\n"
-
- #if ( strcmp(USESTDTRUNK,"NO") != 0 )
- #debug " union\n"
- #debug " {\n"
- #debug concat(" cone { <0, 0, 0>, ",TRUNKBASER,", <0, ",TRUNKLEN,", 0>, ",TRUNKCAPR," }\n")
- #debug " #declare NROFCONES = NROFCONES + 1\n"
- #debug concat(" sphere { <0, ",TRUNKLEN,", 0>, ",TRUNKCAPR," }\n")
- #debug " #declare NROFSPHERES = NROFSPHERES + 1\n"
- #debug concat(" #ifdef ( MOD_TR )\n")
- #debug " // if defined, insert the texture-modifier\n"
- #debug concat(" texture { MOD_TR }\n")
- #debug " #end\n"
- #debug " }\n"
- #else
- #debug " object\n"
- #debug " {\n"
- #debug " NEWTRUNK\n"
- #debug " }\n"
- #end
-
- // Generate th erest of the tree
- // First while-statement: Open all recursion-levels
-
- #while ( INCDEPTH < DEPTH )
- #debug "// Set loop-counter to number of number of branches + difference\n"
- #debug "// in dependance to the actual recursion-step.\n"
- #debug concat("#declare X = ",str(INCDEPTH,0,0),"\n")
- #debug concat("#declare DEPTH_",str(INCDEPTH,0,0)," = (",NRBRANCHES,"+(rand(RANDNRBDIFF_",OBJECTNAME,")*",NRBDIFF,"))*pow(",NRBSCALEMUL,",",str(INCDEPTH,0,0),")+(",NRBSCALEADD,"*",str(INCDEPTH,0,0),")\n")
- #debug concat("#while ( DEPTH_",str(INCDEPTH,0,0)," > 0 )\n")
- #if ( INCDEPTH != DEPTH-1 )
- #debug concat(" // recursion step: ",str(INCDEPTH,0,0),"\n")
- #debug " union\n"
- #debug " {\n"
- #debug " // compute the actual branch-radius\n"
- #debug concat(" #declare ACTRAD = (",RADIUS,"-(rand(RANDRDIFF_",OBJECTNAME,")*",RDIFF,"))*pow(",RADSCALE,",",str(INCDEPTH,0,0),") \n")
- #debug " // compute actual branch-length\n"
- #debug concat(" #declare BLEN_",str(INCDEPTH,0,0)," = (",BLEN,"+(rand(RANDLDIFF_",OBJECTNAME,")*",LDIFF,"))*pow(",RECSCALE,",",str(INCDEPTH,0,0),")\n")
- #debug concat(" cone { <0, 0, 0>, ACTRAD, <0, BLEN_",str(INCDEPTH,0,0),", 0>, ACTRAD*(",RADSCALE,") }\n")
- #debug " #declare NROFCONES = NROFCONES + 1\n"
- #debug concat(" sphere { <0, BLEN_",str(INCDEPTH,0,0),", 0>, ACTRAD*(",RADSCALE,") }\n")
- #debug " #declare NROFSPHERES = NROFSPHERES + 1\n"
-
- #else
- #if ( strcmp(LEAFINC,"YES") = 0 )
- #debug " union\n"
- #else
- #debug " object\n"
- #end
- #debug " {\n"
- #debug " // compute the actual branch-radius\n"
- #debug concat(" #declare ACTRAD = (",RADIUS,"-(rand(RANDRDIFF_",OBJECTNAME,"))*",RDIFF,")*pow(",RADSCALE,",",str(INCDEPTH,0,0),") \n")
- #debug " // lowest branch-level without closing sphere\n"
- #debug concat(" #declare BLEN_",str(INCDEPTH,0,0)," = (",BLEN,"+(rand(RANDLDIFF_",OBJECTNAME,")*",LDIFF,"))*pow(",RECSCALE,",",str(INCDEPTH,0,0),")\n")
- #debug concat(" cone { <0, 0, 0>, ACTRAD, <0, BLEN_",str(INCDEPTH,0,0),", 0>, ACTRAD*",RADSCALE," }\n")
- #debug " #declare NROFCONES = NROFCONES + 1\n"
-
- #if ( strcmp(LEAFINC,"YES") = 0 )
- #debug " // generate the leafs\n"
- #debug " // leaf-counter\n"
- #debug concat(" #declare LEAFCNT = ",NRLEAFS," + (int(rand(RANDNRLDIFF_",OBJECTNAME,")*",NRLDIFF,"))\n")
- #debug " #while ( LEAFCNT > 0 )\n"
- #debug " object\n"
- #debug " {\n"
- #debug " // choose a leaf\n"
- #debug concat(" #switch( int( rand(RANDLEAFSELECT_",OBJECTNAME,") * (",NRLEAFS,"-1) ) )\n")
-
- #declare LCOUNT = 0
- #while ( LCOUNT < NRLEAFINCS )
- #debug concat(" #case ( ",str(LCOUNT,0,0)," )\n")
- #debug concat(" LEAFINC_",str(LCOUNT,0,0),"\n")
- #debug " #break\n"
- #declare LCOUNT = LCOUNT + 1
- #end
- #debug " #else\n"
- #debug " LEAFINC_0\n"
- #debug " #end\n"
- #debug " #declare NROFLEAFS = NROFLEAFS + 1\n"
- #debug " rotate <90, 0, 0>\n"
- #debug concat(" #declare randy = 360*rand(RANDLEAFROT_",OBJECTNAME,")\n")
- #debug concat(" rotate <0, randy, 0>\n")
- #debug concat(" translate <0, rand(RANDLEAFTRANS_",OBJECTNAME,")*BLEN_",str(INCDEPTH,0,0),", 0>\n")
- #debug " }\n"
- #debug " #declare LEAFCNT = LEAFCNT - 1\n"
- #debug " #end\n"
- #end
-
- #end
- #debug "\n"
- #declare INCDEPTH = INCDEPTH+1
- #end
-
-
- // Second while-statement: include texture-modifiers, transformations and closing the recursion-levels
-
- #declare INCDEPTH = DEPTH-1
- #while ( INCDEPTH != -1 )
- #debug concat(" #ifdef ( MOD_",str(INCDEPTH,0,0)," )\n")
- #debug " // if defined, insert texture-modifier\n"
- #debug concat(" texture { MOD_",str(INCDEPTH,0,0)," }\n")
- #debug " #end\n"
- #debug " // branch-inclination\n"
- #debug concat(" #declare randx = (",SLOPEANGLE,"+(rand(RANDSDIFF_",OBJECTNAME,")*",SANGLEDIFF,"))*pow(",ANGLESCALE,",",str(INCDEPTH-1,0,0),")\n")
- #debug concat(" rotate <randx, 0, 0>\n")
- #debug " // rotate within the rotation-range\n"
- #debug concat(" #declare randy = ",ROTRANGE,"*rand(RANDROT_",OBJECTNAME,")\n")
- #debug concat(" rotate <0, randy, 0>\n")
- #if ( INCDEPTH > 0 )
- #debug " // displace at the parent-branch\n"
- #debug concat(" #if ( rand(RANDBT_",OBJECTNAME,") < ",BRANCHTOP," )\n")
- #debug " // move to branch-top\n"
- #debug concat(" translate <0, BLEN_",str(INCDEPTH-1,0,0),", 0>\n")
- #debug " #else\n"
- #debug " // move to a random point\n"
- #debug concat(" translate <0, (BLEN_",str(INCDEPTH-1,0,0),")*rand(RANDBT_",OBJECTNAME,"), 0>\n")
- #debug " #end\n"
- #else
- #debug " // move to the top of the trunk\n"
- #debug concat(" translate <0, ",TRUNKLEN,", 0>\n")
- #end
- #debug " }\n"
- #debug concat(" #declare DEPTH_",str(INCDEPTH,0,0)," = DEPTH_",str(INCDEPTH,0,0)," - 1\n")
- #debug "#end\n"
- #declare INCDEPTH = INCDEPTH-1
- #end
-
- // close the union OBJECTNAME
- #debug "}\n\n"
-
-
- // print out the statistics
- #debug "#statistics \"\\n\\n SELFTREE STATISTICS:\\n\" \n"
- #debug "#statistics \" --------------------------\\n\" \n"
- #debug concat("#statistics concat(\" Objectname : ",OBJECTNAME,"\\n\") \n")
- #debug "#statistics \" --------------------------\\n\" \n"
- #debug "#statistics concat(\" Number of cones : \",str(NROFCONES, 6, 0),\"\\n\") \n"
- #debug "#statistics concat(\" Number of spheres : \",str(NROFSPHERES, 6, 0),\"\\n\") \n"
- #debug "#statistics concat(\" Number of leafs : \",str(NROFLEAFS, 6, 0),\"\\n\") \n"
- #debug "#statistics \" --------------------------\\n\" \n"
- #debug "#statistics concat(\" Total : \",str(NROFLEAFS+NROFSPHERES+NROFCONES, 6, 0),\"\\n\") \n"
-
- #debug "\n\n\n\n\n"
-